require.config({
  baseUrl: '../../../',
  paths: {
    jquery: 'plugins/jQuery/jquery-2.2.3.min',
    flavr: 'plugins/flavr/flavr.min',
    select2: 'plugins/select2/select2.min',
    echarts: 'plugins/echarts/echarts.min',
    public: 'public/js/public.min'
  },
  shim: {
    flavr: {
      deps: ['jquery']
    },
    select2: {
      deps: ['jquery']
    }
  }
});
require(['jquery', 'echarts', 'flavr', 'select2', 'public'], function ($, echarts) {
  $(function(){
    var obj = {
      init: function () {
        this.load();
      },
      load: function () {
        var _this = this;
        $('#header').load('../../head.html', function () {
          $('#navigator').load('../../left-nav.html', function () {
            _this.year = $('.header-select-year').on('change', function () {
              _this.setTitle();
              _this.queryData();
            });

            _this.initChart();
            _this.setTitle();
            _this.queryData();
          });
        });
      },
      setTitle: function () {
        var year = this.year.find('option:selected').text();
        $('.title').html(year + '年' + GetQueryString('name') + '其他');
      },
      queryData: function () {
        var _this = this;
        publicAjax(basePath + 'medical-business', 'post', {
          hospitalId: GetQueryString('id'),
          year: this.year.val()
        }, function (data) {
          var xAxisData = [];
          var seriesData = [[], [], []];
          if (data.ret === 1) {
            var list = data.data || [],
              str = '';
            if (list.length) {
              for (var i = 0; i < list.length; i++) {
                xAxisData.push(fixStr(list[i].monthName));
                seriesData[0].push(fixLine(list[i].bloodPressure));
                seriesData[1].push(fixLine(list[i].feverClinicPersontime));

                str += (
                    '<tr>' +
                    '<td>' + fixStr(list[i].monthName) + '</td>' +
                    '<td class="text-right">' + fixLine(list[i].outpatientPersontime) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].outpatientReturnRate) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].outpatientPerCapitaCost) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].outpatientMedicineRate) + '</td>' +
                    '<td class="text-right">' + fixLine(list[i].discharges) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].averageStayLength) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].averageHospitalizationCost) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].hospitalizationMedicineRate) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].medicineRate) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].hygienicMaterialRate) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].level3Level4OperationRate) + '</td>' +
                    '<td class="text-right">' + fixLine2(list[i].selectiveOperationRate) + '</td>' +
                    '<td class="text-right">' + fixLine(list[i].medicalEvent) + '</td>' +
                    '<td class="text-right">' + fixLine(list[i].administrativePenaltyCases) + '</td>' +
                    '<td class="text-right">' + fixLine(list[i].bloodPressure) + '</td>' +
                    '<td class="text-right">' + fixLine(list[i].feverClinicPersontime) + '</td>' +
                    '</tr>'
                );
              }
              _this.chartOption.xAxis.data = xAxisData;
              _this.chartOption.series[0].data = seriesData[0];
              _this.chartOption.series[1].data = seriesData[1];
              _this.chart.setOption(_this.chartOption);
              _this.resizeChart();
            } else {
              flavrShowByTime('暂无数据！', null, 'info', false);
              str = '<tr><td colspan="10" class="text-center">暂无数据!</td></tr>';
            }
            $('#table-data').find('tbody').html(str);
          } else {
            flavrShowByTime(data.msg, null, 'error', false);
          }
        });
      },
      chartEl: $('#chart'),
      initChart: function () {
        this.chart = echarts.init(this.chartEl[0]);
      },
      resizeChart: function () {
        var chartParent = this.chartEl.parent();
        this.chartEl.width(chartParent[0].clientWidth);
        this.chartEl.height(chartParent[0].clientHeight);
        this.chart.resize();
      },
      chartOption: {
        color: ['#01b2f5', '#cedc3f'],
        tooltip : {
          trigger: 'axis'
        },
        legend: {
          data:['35岁以上人群首诊测压人数', '发热门诊就诊人次数'],
          textStyle: {
            color: '#333'
          }
        },
        xAxis: {
          name: '',
          type: 'category',
          data: [],
          nameTextStyle: {
            color: '#333'
          },
          axisLine: {
            lineStyle: {
              color: '#333'
            }
          }
        },
        yAxis: [{
          name: '人',
          type: 'value',
          nameTextStyle: {
            color: '#333'
          },
          position: 'left',
          axisLine: {
            lineStyle: {
              color: '#333'
            }
          },
          splitLine: {
            show: false
          }
        },{
          name: '人次',
          type: 'value',
          nameTextStyle: {
            color: '#333'
          },
          position: 'right',
          axisLine: {
            lineStyle: {
              color: '#333'
            }
          },
          splitLine: {
            show: false
          }
        }],
        series: [{
          name: '35岁以上人群首诊测压人数',
          data: [],
          type: 'line',
          barGap: 0,
          yAxisIndex: 0,
          itemStyle:{
            normal:{
              lineStyle:{
                width:3
              }
            }
          }
        }, {
          name: '发热门诊就诊人次数',
          data: [],
          type: 'line',
          yAxisIndex: 1,
          itemStyle:{
            normal:{
              lineStyle:{
                width:3
              }
            }
          }
        }]
      }
    };

    obj.init();
  });
});